//
//  String.Decode64.swift
//  App_Common_FoundationExtensions
//
//  Created by 董宝龙 on 2021/6/25.
//

import Foundation

public extension String {
    var base64: String? {
        let utf8EncodeData = data(using: String.Encoding.utf8, allowLossyConversion: true)
        let base64String = utf8EncodeData?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: UInt(0)))
        return base64String
    }

    var decodeBase64: String? {
        guard let base64Data = Data(base64Encoded: self, options: Data.Base64DecodingOptions(rawValue: 0)) else { return nil }
        let stringWithDecode = String(data: base64Data as Data, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
        return stringWithDecode
    }
}
